package com.mybatis_plusnew.shnc.apis.conntroller;

import javax.servlet.http.HttpServletRequest;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mybatis_plusnew.shnc.apis.mapper.ReportPenetrationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 报表控制层
 */
@RestController
@RequestMapping("/api/reportPenetration")

public class ReportPenetrationConntroller {
    @Autowired
    private ReportPenetrationMapper reportPenetrationMapper;


    @ResponseBody
    @PostMapping("/getHyjyAndTask")
    public List<Map<String,Object>> getHyjyAndTask(HttpServletRequest request){

        QueryWrapper<Map<String,Object>> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status",2); //已归档数据
        queryWrapper.eq("deleted",0); //未被删除数据
        List<Map<String,Object>> getHyjy = reportPenetrationMapper.getHyjy(queryWrapper);

        //获取所有任务
        QueryWrapper<Map<String,Object>> queryWrapper1 = new QueryWrapper<>();
//        queryWrapper1.eq("status",2); //已归档数据
        queryWrapper1.eq("deleted",0); //未被删除数据
        queryWrapper1.eq("select_1711505903223_YWk8w","e0f13da9d1df4bd692518af8430845fe"); //会议任务
        List<Map<String,Object>> getTask = reportPenetrationMapper.getTask(queryWrapper1);

        List<Map<String,Object>> getHyjyAndTask = new ArrayList<>();
        for (int i = 0; i <getTask.size() ; i++) {
            for (int j = 0; j < getHyjy.size(); j++) {
                //只添加一条
                if(getHyjy.get(j).get("表体id").equals(getTask.get(i).get("任务对应会议ID"))){
                    getHyjy.get(j).put("负责人",getTask.get(i).get("负责人"));
                    getHyjy.get(j).put("负责人_ID",getTask.get(i).get("负责人_ID"));
                    List<String> jsonData = JSONObject.parseObject((String) getTask.get(i).get("计划时间"), List.class);
                    getHyjy.get(j).put("计划结束",jsonData.get(1));
                    getHyjy.get(j).put("任务对应会议ID",getTask.get(i).get("任务对应会议ID"));
                    getHyjyAndTask.add(getHyjy.get(j));
                }
            }
        }
        System.out.println("join1");
        for (int i = 0; i <getHyjyAndTask.size() ; i++) {
            System.out.println(getHyjyAndTask.get(i));
        }
        return getHyjyAndTask;
    }
}


